<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

	class OrderParkController extends AdminBaseController
	{

		/*园区房间列表页*/	
		public function index(){
			
		$site_type = $this->request->param('site_type_id',0);
		if($site_type){
			$where['site_type_id'] = $site_type;	
		}
					
		/**搜索条件**/
		$site_name = $this->request->param('site_name');
		$address = $this->request->param('address');

		if ($site_name) {
       	   $where['site_name'] = ['like', "%$site_name%"];
        }

        if ($address) {
            $where['address'] = ['like', "%$address%"];
        }

            $list=Db::name('site')->alias('s')->where($where)->join('incubator i','i.id=s.incubator_id')->paginate(5);
			//$list=Db::name('station')->alias('a')->join('cx_incubator w','w.id=a.incubator_id')->paginate(5);
			$page=$list->render();
			$this->assign("page", $page);

			$this->assign("list", $list);
			return $this->fetch();
		}



		/*园区添加*/		
		public function addCustomer(){
			$data['customer_name'] = $this->request->param('customer_name','');
			$data['customer_type'] = $this->request->param('customer_type',0);
			$data['linkman'] = $this->request->param('linkman','');
			$data['mobile'] = $this->request->param('mobile',0);
			$data['position'] = $this->request->param('position','');
			$data['field'] = $this->request->param('field',0);
			$data['stage'] = $this->request->param('stage',0);
			$data['address'] = $this->request->param('address','');
			$data['source'] = $this->request->param('source','');
			$data['follow_state'] = $this->request->param('follow_state',0);
			$data['salesman'] = $this->request->param('salesman','');
			$data['salesmobile'] = $this->request->param('salesmobile',0);
			$data['remark'] = $this->request->param('remark','');
			$data['file'] = $this->request->param('file','');
			// echo $incubator_name ;
			// if($type_id==1){
			// 	$station_	
			// }					

			// echo $type_id;

			$add=Db::name('customer')->insert($data);
			
			if($add){
				$this->success('添加成功','Customer/index');
			}else{
				$this->error('添加失败');
			}	





		}
		/*详情*/
		public function detailCustomer(){
			$where=array();
			$id= $this->request->param('id',0,'intval');
			if($id){
				$where['id']= $id;
			}else{
				// dump(info_back('','id为空',false));
				// exit;
				return info_back('','id为空',false);
			}
			$detail= Db::name('customer')->where($where)->find();
			 // dump($detail);
			// echo Db::name('station')->getLastSql();
			
			$this->assign('detail',$detail);
			return $this->fetch();
		}

		/*编辑园区*/	
		public function editCustomer(){
			if($_POST){
				$edit = Db::name('customer')->update($_POST);
				if($edit){
					$this->success('编辑成功');
				}
			}
			$where=array();
			$id= $this->request->param('id',0,'intval');
			if($id){
				$where['id']= $id;
			}else{
				return info_back('','id不能为空',false);
			}
			$detail= Db::name('customer')->where($where)->find();
			 dump($detail);
			// exit;
			$this->assign('detail',$detail);
			$this->fetch();

		}


		/*删除园区*/
		public function delCustomer(){
			$data['id']= $this->request->param('id',0,'intval');

			$data['status']=0;

			$del=Db::name('customer')->update($data);
			if($del){
				return info_back('','删除成功',true);
			}else{
				return info_back('','删除失败',false);
			}

		}	


























	}